﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using A2DFramework.OSGI.Configuration;

namespace A2DFramework.OSGI.ConsoleLauncher
{
    class Program
    {
        private static AppDomain appDomain;
        static void Main(string[] args)
        {
            string modulePath=args[0];

            string manifestPath = System.IO.Path.Combine(modulePath, ManifestsConfigParser.ManifestFileName);
            ModuleInfo moduleInfo=ManifestsConfigParser.ParseDetailSettings(manifestPath);

            AppDomainSetup setup = new AppDomainSetup();
            setup.ApplicationBase = modulePath;
            appDomain = AppDomain.CreateDomain(moduleInfo.Name, null, setup);
            ILaunchEntry launchEntry = (ILaunchEntry)appDomain.CreateInstanceAndUnwrap(moduleInfo.Assembly, moduleInfo.LaunchEntry);

            List<string> newArgs = new List<string>();
            foreach (var s in args.Skip(1))
                newArgs.Add(s);

            launchEntry.Launch(newArgs.ToArray());
        }
    }
}
